package org.zsl.mybatis.mapper;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;
import org.zsl.mybatis.model.Item;

import java.util.List;

public interface ItemMapper {


    @Select("select * from item where item_id=#{itemId}")
    @Results(id = "itemMapper",value = {
            @Result(column = "item_id",property = "itemId"
                    ,jdbcType = JdbcType.INTEGER,id = true),
            @Result(column = "product_id",property = "product"
                    ,one = @One(select = "org.zsl.mybatis.mapper.ProductMapper.selectById"
                    ,fetchType = FetchType.LAZY)),
            @Result(column = "quantity",property = "quantity",jdbcType = JdbcType.INTEGER)
    })
    Item selectById(Integer itemId);

    /**
     *  学生自行完成
     * */
    List<Item> selectAll();

    @Select("select * from item where order_id=#{orderId}")
    @ResultMap(value = "itemMapper")
    List<Item> selectByOrderId(Integer orderId);


}
